/**
 * Created by Quaye on 2016/12/22.
 */

var JsLAM = null;
var userId = 'xiaodeng';
var portraitUrl = '';
var nickName = '';


function StartFromHere(files) {
    debug.out(" Start Function in.");
    /********************************
     *            Member            *
     ********************************/
    //192.168.0.110
    var m_userId = "xiaodeng";
    var m_postUrl = "http://lookatme-plus.com/api/back/game/records/get";

    var m_postData = {
        game_id: "5",
        socket_type: "1",
        device_id: "3",
        token:"91yrf3QKQStxlIX3RLVOUwVJAXRk28FFLGwh"
    };

    /********************************
     *            Function          *
     ********************************/
    function m_Post(URL, PARAMS) {
        $.post(URL, PARAMS, function (data) {
            console.log(data);
            var m_postResult = data;
            console.log(m_postResult);
            if (m_postResult.status == "0") {
                JsLAM = new JisightLookAtMeClient(m_userId);                        //userId 初始化LookAtMe
                JsLAM.JLAM_Event_Fir = JlamEventHandle;
                JsLAM.TryConnect(m_postResult.message.ip,
                    m_postResult.message.port,
                    m_postResult.message.roomId,
                    m_postResult.message.gameSign);
            } else {
                console.log("post default.×××××××××")
            }
        });
    }

    function JlamEventHandle(eveArgs) {
        console.log("【测试的回调】: --- in ---");
        console.log(eveArgs);
        switch (eveArgs.status) {
            case  LAM_STATUS.DATA_ROOM_VERIFY_T:
                console.log("验证 成功");
                console.log(screen.width, screen.height);
                if (screen.width < screen.height) {
                    //window.location.href = 'prompt.html';
                }
                break;
            case  LAM_STATUS.DATA_ROOM_VERIFY_F:
                console.log("验证 失败");
                //小邓需要时在这里处理：
                break;
            case  LAM_STATUS.DATA_ROOM_STATUS_T:
                console.log("获取状态 成功");
                //小邓需要时在这里处理：
                break;
            case  LAM_STATUS.DATA_ROOM_STATUS_F:
                console.log("获取状态 失败");
                //小邓需要时在这里处理：
                break;
            case  LAM_STATUS.DATA_AWARD_LIST_T:
                console.log("接收到奖励列表 成功");
                //小邓需要时在这里处理：
                break;
            case  LAM_STATUS.DATA_AWARD_LIST_F:
                console.log("接收到奖励列表 失败");
                //小邓需要时在这里处理：
                break;
            case  LAM_STATUS.DATA_RANK_LIST_T:
                console.log("接收到排行榜 成功");
                //小邓需要时在这里处理：
                break;
            case  LAM_STATUS.DATA_RANK_LIST_F:
                console.log("接收到排行榜 失败");
                //小邓需要时在这里处理：
                break;
            case  LAM_STATUS.DATA_CUSTOM_MSG_T:
                console.log("自定义数据接收 成功");
                var receiveData = JSON.parse(eveArgs.message);
                console.log(receiveData);

                //小邓需要时在这里处理：
                break;
            case  LAM_STATUS.DATA_CUSTOM_MSG_F:
                console.log("自定义数据推送 失败");
                //小邓需要时在这里处理：
                break;
        }
        console.log("【测试的回调】: --- out ---");
    }

    /********************************
     *              Run             *
     ********************************/
    if (JsLAM != null) {
        debug.outWarning(" web socket is running . don't run it again.");
        return;
    }
    debug.needLog = false;
    m_Post(m_postUrl, m_postData);
    debug.out(" Start Function out.");
}

function GetRoomStatus() {
    JsLAM.GetGameStatus();
}

function LoginGame() {
    var loginInfo = {
        userId : userId,
        type: '201',
        portraitUrl : portraitUrl,
        nickName: nickName
    };
    JsLAM.SndMsgToOther(["Calculator"], loginInfo);
}

function LogoutGame() {
    var logout = {
        userId : userId,
        type: '202'
    };
    JsLAM.SndMsgToOther(["Calculator"], logout);
}

function joyStickSnd (mesaage){
    console.log(mesaage);
    var joyStickInfo = {
        userId : userId,
        type: '203',
        data: mesaage
    };
    JsLAM.SndMsgToOther(["Calculator"], joyStickInfo);
}
function getPermit (userinfo){
    var joyStickInfo = {
        userId : userId,
        type: '200',
        data: userinfo
    };
    console.log(joyStickInfo);
    JsLAM.SndMsgToOther(["Calculator"], joyStickInfo);
}
function accelerateSnd (isAccelerate){
    var accelerateInfo = {
        userId: userId,
        type: '204',
        data: isAccelerate
    };
    JsLAM.SndMsgToOther(["Calculator"], accelerateInfo);
}

function SndMsgToOther() {
    JsLAM.SndMsgToOther(["Calculator"], "数据更新测试！！！");
}

function ReSetRoomStatus() {
    var m_resetStatusUrl = "http://192.168.0.111/records/update";
    var m_resetRoomStatus = {
        gameId: "01-201608081436332560",
        ip: "192.168.0.110",
        roomId: "d20160812173632639[*LSR*]28fe7c48e096d2b9a821",
        gameSign: "756cd9098b20cb49329ecbacb538d42f",
        players: "",
        status: "WAITING",
        token: "91yrf3QKQStxlIX3RLVOUwVJAXRk28FFLGwh"
    }
    $.post(m_resetStatusUrl, m_resetRoomStatus, function (data) {
        console.log(data);

    });
}
